from django.db import models


# Create your models here.
class ComicKind(models.Model):
    """
    漫画分类
    """
    kind_name = models.CharField(max_length=10, verbose_name='漫画分类名称', unique=True)
    kind_desc = models.TextField(max_length=1000, verbose_name='分类的说明')

    def comic_list(self):
        return ','.join([i.book_name for i in self.kind_comic.all()])

    def __str__(self):
        return self.kind_name

    class Meta:
        verbose_name = '漫画分类'
        verbose_name_plural = verbose_name


class ComicInfo(models.Model):

    id = models.CharField(max_length=50, primary_key=True, verbose_name='漫画id')
    book_name = models.CharField(max_length=50, unique=True, verbose_name='漫画名字')
    description = models.TextField(max_length=1000, blank=True, verbose_name='漫画描述')
    popularity = models.CharField(max_length=50, blank=True, verbose_name='漫画人气')
    book_url = models.URLField(blank=True, verbose_name='漫画网站')
    book_img = models.URLField(blank=True, verbose_name='漫画图片url')
    content_url = models.URLField(blank=True, verbose_name='漫画阅读url')
    book_area = models.CharField(max_length=50, blank=True, verbose_name='漫画地区')
    book_type = models.CharField(max_length=50, blank=True, verbose_name='漫画分类')
    kind = models.ManyToManyField(ComicKind, verbose_name='漫画分类', blank=True, related_name='kind_comic')

    def kind_list(self):
        return ','.join([i.kind_name for i in self.kind.all()])

    def __str__(self):
        return self.book_name

    class Meta:
        verbose_name = '漫画名称'
        verbose_name_plural = verbose_name


class ComicIndex(models.Model):
    """
    单本漫画  主页面，所有章节显示
    """
    id = models.CharField(max_length=50, primary_key=True, verbose_name='章节id')
    catalog_title = models.CharField(max_length=50, blank=True, unique=False, verbose_name='章节名字')
    catalog_desc = models.TextField(max_length=1000, default=None, null=True, verbose_name='章节描述')
    belongto_comic = models.ForeignKey(ComicInfo, related_name='comic_index', verbose_name='所属漫画')
    catalog_url = models.URLField(blank=True, verbose_name='章节URL')

    def __str__(self):
        return self.catalog_title

    class Meta:
        verbose_name = '漫画主页'
        verbose_name_plural = verbose_name


class ComicDetail(models.Model):
    """
    单本漫画  详情页面，显示单个章节内容
    """
    detail_content = models.URLField(verbose_name='单个章节详情页面')
    detail_desc = models.TextField(max_length=1000, default=None, null=True, verbose_name='漫画描述')
    belongto_catalog = models.ForeignKey(ComicIndex, related_name='comic_detail', verbose_name='所属章节')























